package com.wyp.design.pattern.creational.singleton.serializabledestory;

import java.io.Serializable;

/**
 * 饿汉式中变量是可以使用final进行修饰的，懒汉式不可以
 *
 * @author: yipeng.wang01@hand-china.com-25490
 * @TIME: 2020/1/2/17:00
 **/
public class HungrySingleton implements Serializable {
    private final static HungrySingleton hungrySingleton;
    //当然初始化操作也可以放在静态代码块中

    static {
        hungrySingleton = new HungrySingleton();
    }

    private HungrySingleton() {
    }

    public static HungrySingleton getInstance() {
        return hungrySingleton;
    }

    private Object readResolve() {
        return hungrySingleton;
    }
}
